GetSlaveById

Gets detailed information from a specified slave using an ID.

Syntax

KsError GetSlaveById(
     int SlaveId,
     SlaveStatus* Details
);

Parameters

SlaveId: the index of a slave array. When EtherCAT is started, this index has the same value as the SlaveId, which corresponds to the position of the slave in the network. Please note that after EtherCAT is started in the Operational (Op) state, any addition or removal of slaves from the network will change the position of the slaves in the network (SlaveId). Nevertheless, the index of the slave will remain the same. Newly added devices will be added in the back of the slave array. For all slaves after the change, the index and SlaveId will no longer match. This behavior is only available for physical devices; simulated devices are inapplicable. Please refer to the use cases in EnableHotConnect for more details.

Details: pointer to the SlaveStatus structure that receives the detailed information about the slave's status.

Return value

If the function succeeds, it returns errNoError, otherwise an error code. For more information about the error code, see the KsError list.

Remarks

Retrieves details about a specified slave using the slave’s position in the EtherCAT loop. Since it uses the slave ID, it doesn't use the alias information. It works only for real slave modules without separating axes or I/Os. Use after the KINGSTAR Subsystem starts.

Usable EtherCAT states

ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP

Example

Copy
SlaveStatus slaveStatus = { 0 };
nRet = GetSlaveById(0, &slaveStatus);
if (nRet == errNoError)
{
    // Check the slave information in the SlaveStatus structure.
    RtPrintf("Device 0 %s: Vendor 0x%x, Product 0x%x, Revision 0x%x, Serial 0x%x\n",
             slaveStatus.Name, slaveStatus.VendorId, slaveStatus.ProductCode,
             slaveStatus.RevisionNumber, slaveStatus.SerialNumber);
    RtPrintf("Address: Auto %d, Fixed %d, Alias %d\n",
             slaveStatus.SlaveId, slaveStatus.PhysAddress, slaveStatus.AliasAddress);
    RtPrintf("PDO: Input len %d, Output len %d, Index offset 0x%x\n",
             slaveStatus.InputLength, slaveStatus.OutputLength, slaveStatus.VariableIndexOffset);
    RtPrintf("State %d, Cycle time %d\n", slaveStatus.State, slaveStatus.CycleTime);
}

Requirements

  RT Win32
Minimum supported version 4.0 4.0
Header ksapi.h ksapi.h
Library KsApi_Rtss.lib KsApi.lib

See also

GetIOByIndex

GetStatus

RequestSlaveState